//
//  main.m
//  颜色 管理
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 yh. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Color.h"

int main(int argc, const char * argv[]) {
    NSString *path = @"/Users/dllo/DLS160710/Objective-C/HomeWork/Work_4/Work_4/crayons.txt";
    // 通过路径读取文件中的字符
    NSString *souStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@", souStr);
    NSMutableDictionary *colorDic = [NSMutableDictionary dictionary];
    NSArray *allColorArr = [souStr componentsSeparatedByString:@"\n"];
    NSLog(@"%@", allColorArr);
    for (NSInteger i = 0; i < allColorArr.count; i++) {
        if ([allColorArr[i] length] > 0) {
            NSArray *colorArr = [allColorArr[i] componentsSeparatedByString:@"#"];
            [colorDic setObject:[colorArr lastObject] forKey:[colorArr firstObject]];
        }
    }
    NSLog(@"%@", colorDic);
    
    NSArray *keyArr = [colorDic allKeys];
    NSMutableDictionary *newDic = [NSMutableDictionary dictionary];
    for (NSInteger i = 0; i < keyArr.count; i++) {
        NSString *bigLetter = [keyArr[i] substringWithRange:NSMakeRange(0, 1)];
        NSMutableArray *valueArr = [newDic objectForKey:bigLetter];
        Color *color = [[Color alloc] init];
        color.colorName = keyArr[i];
        color.colorValue = [colorDic objectForKey:keyArr[i]];
        if (valueArr == nil) {
            valueArr = [NSMutableArray arrayWithObject:color];
            [newDic setObject:valueArr forKey:bigLetter];
        } else {
            [valueArr addObject:color];
        }
    }
    NSLog(@"%@", newDic);
    
    
    
    return 0;
}
